import { defineStore } from "pinia";
export interface ShopcartData{
  id: number,
  goodsName: string,
  goodsImg: string
  price: number
  isChecked: boolean
  count: number
}
const useShopcartStore = defineStore('shopcart', {
  state: () => ({
    shopcartList: [
      {
        id: 1,
        goodsName: '摆挂两用智能喷香机',
        goodsImg: 'https://yanxuan-item.nosdn.127.net/0f920ed89dc0b78b7f1e9cb486e585b0.png?type=webp&imageView&quality=75&thumbnail=750x0',
        count: 1,
        price: 29.9,
        isChecked: false
      },
      {
        id: 2,
        goodsName: '运动健身便携Tritan水杯 （800ml/ 550ml）',
        goodsImg: 'https://yanxuan-item.nosdn.127.net/7b5380ed3dedab7d966a7fc743c1038a.jpg?type=webp&imageView&quality=65&thumbnail=330x330',
        count: 3,
        price: 68,
        isChecked: false
      },
      {
        id: 3,
        goodsName: '【礼盒】经典款EMS颈椎按摩仪',
        goodsImg: 'https://yanxuan-item.nosdn.127.net/6644ed15ed87954534f520806689a533.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
        count: 1,
        price: 179,
        isChecked: true
      }
    ]
  }),
  actions: {
    changeGoodsStatus(index:number){
      this.shopcartList[index].isChecked = !this.shopcartList[index].isChecked
    },
    changeGoodsCount(index:number,type:string){
      if(type === 'add'){
        this.shopcartList[index].count++
        this.shopcartList[index].isChecked = true
      }else{
        if(this.shopcartList[index].count<=1){
          return
        }else{
          this.shopcartList[index].count--
        }
      }
    },
    changeAllGoosStatus(flag:boolean){
      this.shopcartList.forEach((item)=>{
        item.isChecked = flag
      })
    }
  }
})

export default useShopcartStore